﻿#ifndef _MBLOCK_H_
#define _MBLOCK_H_

#include "nlist.h"
#include "sys_plat.h"
#include "nlocker.h"

// 内存块管理器结构
typedef struct _mblock_t
{
    nlist_t free_list;   // 用于存放空闲内存块
    void *start;         // 指向空闲内存块的起始地址
    nlocker_t locker;    // 用于控制同步的锁
    sys_sem_t alloc_sem; // 分配内存块信号量字段
} mblock_t;

net_err_t mblock_init(mblock_t *mblock, void *mem, int blk_size, int cnt, nlocker_type_t type);
void *mblock_alloc(mblock_t *mblock, int ms);
int mblock_free_block_cnt(mblock_t *mblock);
void mblock_free(mblock_t *mblock, void *block);
void mblock_destroy(mblock_t *mblock);

#endif